using System;
using System.Collections.Generic;
using System.Linq;
using Systemathics.FrameWork;

namespace Systemathics.Indicators
{
    public sealed class TDCamouflage : Indicator
    {
        private readonly Queue<Bar> PastBar;

        public TDCamouflage(Instrument instr, Data dt, BarType bt, int value) : base(instr, dt, bt, value)
        {
            PastBar = new Queue<Bar>();
        }
        protected override void Calculate(object price)
        {
            var Bar = price as Bar;

            if (PastBar.Count < 3)
                PastBar.Enqueue(Bar.Clone() as Bar);
            else
            {
                PastBar.Enqueue(Bar.Clone() as Bar);

                if ((Bar.Close < PastBar.ElementAt(2).Close) && (Bar.Close > Bar.Open) && (Bar.Low < PastBar.ElementAt(1).Close) && (Bar.Low < PastBar.First().Close))
                {
                    Add(Time.Now, +1);
                    IndicatorCalculated(this);
                }
                else if ((Bar.Close > PastBar.ElementAt(2).Close) && (Bar.Close < Bar.Open) && (Bar.High > PastBar.ElementAt(1).High) && (PastBar.Last().High > PastBar.ElementAt(1).Close))
                {
                    Add(Time.Now, -1);
                    IndicatorCalculated(this);
                }


                //if ((bar.Close < Bars.Ago(1).Close) && (bar.Close > bar.Open) && (bar.Low < Bars.Ago(2).Low) && ((bar.Low < Bars.Ago(3).Close)))
                //    Camouflage = +1;
                //else if ((bar.Close > Bars.Ago(1).Close) && (bar.Close < bar.Open) && (bar.High > Bars.Ago(2).High) && ((bar.High > Bars.Ago(3).Close)))
                //    Camouflage = -1;



                PastBar.Dequeue();
            }
        }
    }
}